﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CreateWPOnRobotTCPF.CUiCreateWpOnTCPFCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.CreateWeldPoint;
using System.Reflection;
using System.Resources;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.PrivateImplementationDetails;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.CreateWPOnRobotTCPF;

[TxPowerEngineeringCommandCategory]
public class CUiCreateWpOnTCPFCmd : TxButtonCommand
{
  private CApCreateWpOnTCPFEnable m_createWPEnabler;
  private CUiCreateWpOnTCPFTCDlg _createWPonTCPFTCForm;
  private ITxObject _prevWeldContainer;
  private ITxObject _prevWeldOperation;

  public CUiCreateWpOnTCPFCmd() => this.m_createWPEnabler = new CApCreateWpOnTCPFEnable();

  public virtual void Execute(object cmdParams)
  {
    Cursor current = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    try
    {
      if (TxTcUtilities.IsTcAnyPlatform)
      {
        this._createWPonTCPFTCForm = new CUiCreateWpOnTCPFTCDlg();
        this.InitTCFormWithLastUsedObjects();
        ((Form) this._createWPonTCPFTCForm).FormClosed += new FormClosedEventHandler(this._createWPonTCPFTCForm_FormClosed);
        ((Control) this._createWPonTCPFTCForm).Show();
      }
      else
        new CApCreateWpOnTCPFMgr().CreateWpOnRobotTCPF();
    }
    finally
    {
      Cursor.Current = current;
    }
  }

  public virtual string Category => this.GetResourceManager().GetString("WELD_CMD_CATEGORY");

  public virtual string Name => this.GetResourceManager().GetString("WELD_CMD_NAME");

  private ResourceManager GetResourceManager()
  {
    Assembly assembly = ((object) this).GetType().Assembly;
    return new ResourceManager(assembly.GetName().Name + ".StringTable", assembly);
  }

  public virtual string Bitmap => this.GetResourceManager().GetString("WELD_CMD_BITMAP");

  public virtual string[] AdvancedDescriptions => TxCallMessages.CollectMessages((ITxCommand) this);

  public virtual string Description => this.GetResourceManager().GetString("WELD_CMD_DESCRIPTION");

  public virtual string Tooltip => this.GetResourceManager().GetString("WELD_CMD_TOOLTIP");

  public virtual ITxImage Image => (ITxImage) TxImageManager.GetImageByKey("CreateWeldPointOnTcpf");

  public virtual ITxCommandEnabler CommandEnabler => (ITxCommandEnabler) this.m_createWPEnabler;

  public virtual bool Licensed => TxCommandLicenser.CreateWeldPointsOnRobotTcpf;

  private void InitTCFormWithLastUsedObjects()
  {
    if (!CApCreateWpTCLogic.IsWpConfiguredAsPrivate() && this._prevWeldContainer != null && this._prevWeldContainer.IsValid())
      this._createWPonTCPFTCForm.txebWeldContainer.Object = this._prevWeldContainer;
    if (this._prevWeldOperation == null || !this._prevWeldOperation.IsValid())
      return;
    this._createWPonTCPFTCForm.txebWeldOperation.Object = this._prevWeldOperation;
  }

  private void _createWPonTCPFTCForm_FormClosed(object sender, FormClosedEventArgs e)
  {
    if (((Form) this._createWPonTCPFTCForm).DialogResult == DialogResult.Yes)
    {
      if (!CApCreateWpTCLogic.IsWpConfiguredAsPrivate())
        this._prevWeldContainer = this._createWPonTCPFTCForm.txebWeldContainer.Object;
      this._prevWeldOperation = this._createWPonTCPFTCForm.txebWeldOperation.Object;
    }
    this._createWPonTCPFTCForm = (CUiCreateWpOnTCPFTCDlg) null;
  }
}
